<template>
  <el-dialog 
    title="设置" 
    :visible="visible"
    @close="$emit('update:visible', false)"
    :close-on-click-modal="false"
    width="400px"
  >
    <el-form :model="form" label-width="80px">
      <el-form-item label="单图成本">
        <el-input 
          v-model.number="form.cost_per_map" 
          @change="handleConfigChange"
        ></el-input>
      </el-form-item>
      
      <el-form-item label="透明度">
        <el-slider 
          v-model="form.opacity" 
          :min="0.1" 
          :max="1.0" 
          :step="0.1"
          @change="updateOpacity"
        ></el-slider>
        <span>{{ form.opacity.toFixed(1) }}</span>
      </el-form-item>
      
      <el-form-item label="税收设置">
        <el-radio-group 
          v-model="form.tax" 
          @change="handleConfigChange"
        >
          <el-radio :label="0">不计税</el-radio>
          <el-radio :label="1">计税</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
export default {
  name: 'SettingsWindow',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    config: {
      type: Object,
      default: () => ({
        cost_per_map: 0,
        opacity: 1.0,
        tax: 0
      })
    }
  },
  data() {
    return {
      form: { ...this.config }
    }
  },
  watch: {
    config(newVal) {
      this.form = { ...newVal }
    }
  },
  methods: {
    handleConfigChange() {
      this.$emit('update-config', { ...this.form })
    },
    updateOpacity(value) {
      this.form.opacity = value
      this.handleConfigChange()
    }
  }
}
</script>